<?php
if(defined("_PARA_CHATMSG"))
    return;
define("_PARA_CHATMSG", 1);

require_once "TextFormatter.php";

class ChatMessage extends HTMLable {

    public $id;
    public $screen_name;
    public $uid;
    public $text;
    public $time;

    // private var to avoid it being serialized by json_encode
    // use accessor method instead
    private $ip;

    public function ChatMessage( $id, $screen_name, $uid, $text, $time, $ip ) {
        $this->id          = $id;
        $this->screen_name = $screen_name;
        $this->uid         = $uid;
        $this->text        = $text;
        $this->time        = $time;
        $this->ip          = $ip;
    }


    // comparision function for sorting by id in descending order
    public static function cmp($a, $b) {
        if($a->id == $b->id)
            return 0;
        return ( $a->id < $b->id ) ? 1 : -1;   
    }

    public function get_ip() {
        return $this->ip;
    }


    public function htmlize( $options ) {
        echo "<div class=\"para_chat_shout\" id=\"para_chat_shout_".$this->id . "\">";
        echo "<span class=\"para_chat_shout_time\">",
            Helpers::format_short_tstamp( $this->time );
        echo "</span>";
        echo "<span class=\"para_chat_shout_name\">",
            htmlspecialchars( $this->screen_name ), ": ",
            "</span>";
            echo "<span class=\"para_chat_shout_text\">",
                TextFormatter::format_text($this->text ),
                "</span>";
        echo "</div>\n";
    }

}



?>